<template>
  <j-modal
    title="新增关联"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-cascader
      :options="options"
      :show-search="{ filter }"
      placeholder=""
      @change="onChange"
      style="width: 300px"
    ></a-cascader>
  </j-modal>
</template>

<script>
import {getAction} from "@/api/manage";

export default {
  name: 'CascadeModal',
  components: {},
  data() {
    return {
      title: '',
      width: 350,
      visible: false,
      disableSubmit: false,
      options: [],
      url: {
        category: "/category/pmsCategory/getCascadeTree"
      },
      model: {}
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    onChange(value, selectedOptions) {
      this.model.value = value;
      this.model.selectedOptions = selectedOptions;
    },
    filter(inputValue, path) {
      return path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
    },
    loadData() {
      console.log("loadData")
      getAction(this.url.category).then(res => {
        if (res.success) {
          this.options = res.result
        }
      }).finally(() => {

      })
    },
    show() {
      console.log("show")
      this.visible = true
    },
    close() {
      this.$emit('close');
      this.visible = false;
    },
    handleOk() {
      this.$emit('ok', this.model.value, this.model.selectedOptions);
      this.visible = false;
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>